package com.hugesoft.jxgs.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hugesoft.jxgs.R;
import com.hugesoft.jxgs.activity.base.BaseActivity;
import com.hugesoft.utils.Util;

public class CheckUserVerifyActivity extends BaseActivity implements
		OnClickListener {
	private EditText etVerifyCode;
	private Button btnnext, btnhelp;

	private static String md5weburl = "http://tool.chinaz.com/Tools/MD5.aspx";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activitycheckuserverify);
		etVerifyCode = (EditText) findViewById(R.id.etverifycode);
		btnnext = (Button) findViewById(R.id.nextstep);
		btnnext.setOnClickListener(this);
		btnhelp = (Button) findViewById(R.id.help);
		btnhelp.setOnClickListener(this);

		((TextView)findViewById(R.id.titleTextView)).setText("激活");
		findViewById(R.id.backImg).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				showAlertDialog("提示", "确定退出程序吗?", "确定", "取消",
						new LeftButtonclickListener() {

							@Override
							public void onLeftBtnClick() {
								// TODO Auto-generated method stub
								backToDesk();
							}
						}, new RightButtonclickListener() {

							@Override
							public void onRightBtnClick() {
								// TODO Auto-generated method stub

							}
						});
			}
		});
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.nextstep:
			if (etVerifyCode.getText().toString()
					.equalsIgnoreCase("CBB9FC602472DB44")) {
				gotoLoginActivity();
			}
			else
			{
				Util.showToast(CheckUserVerifyActivity.this, "请输入正确的验证码");
			}
			break;
		case R.id.help:
			Uri uri = Uri.parse(md5weburl);
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
			break;
		default:
			break;
		}
	}

    private void gotoLoginActivity(){
    	Intent intent = new Intent(CheckUserVerifyActivity.this,LoginActivity.class);
    	SharedPreferences sPreferences = this.getSharedPreferences(getResources().getString(R.string.shardpreference_verified), MODE_PRIVATE);
    	Editor editor = sPreferences.edit();
    	editor.putBoolean("verified", true);
    	editor.commit();
    	startActivity(intent);
    	finish();
    }
}
